/*
 * CC3OpenGLES11Hints.m
 *
 * cocos3d 0.6.1
 * Author: Bill Hollings
 * Copyright (c) 2010-2011 The Brenwill Workshop Ltd. All rights reserved.
 * http://www.brenwill.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * http://en.wikipedia.org/wiki/MIT_License
 * 
 * See header file CC3OpenGLES11Hints.h for full API documentation.
 */

#import "CC3OpenGLES11Fog.h"


#pragma mark -
#pragma mark CC3OpenGLES11StateTrackerFogColor

//@implementation CC3OpenGLES11StateTrackerFogColor
//
//-(void) setGLValue {
//	glFogfv(name, (GLfloat*)&value);
//}
//
//+(CC3GLESStateOriginalValueHandling) defaultOriginalValueHandling {
//	return kCC3GLESStateOriginalValueReadOnceAndRestore;
//}
//
//@end

CC3OpenGLES11StateTrackerFogColor::CC3OpenGLES11StateTrackerFogColor()
{
}

CC3OpenGLES11StateTrackerFogColor::~CC3OpenGLES11StateTrackerFogColor()
{
}

CC3OpenGLES11StateTrackerFogColor* CC3OpenGLES11StateTrackerFogColor::trackerForState(GLenum aName)
{
	CC3OpenGLES11StateTrackerFogColor* pState = new CC3OpenGLES11StateTrackerFogColor;
	if (pState) 
	{
		pState->autorelease();
		pState->initForState(aName, NULL);
		return pState;
	}
	
	return NULL;
}

void CC3OpenGLES11StateTrackerFogColor::setGLValue()
{
	glFogfv(name, (GLfloat*)&value);
}

CC3GLESStateOriginalValueHandling CC3OpenGLES11StateTrackerFogColor::defaultOriginalValueHandling()
{
	return kCC3GLESStateOriginalValueReadOnceAndRestore;
}

#pragma mark -
#pragma mark CC3OpenGLES11StateTrackerFogFloat

//@implementation CC3OpenGLES11StateTrackerFogFloat
//
//-(void) setGLValue {
//	glFogf(name, value);
//}
//
//+(CC3GLESStateOriginalValueHandling) defaultOriginalValueHandling {
//	return kCC3GLESStateOriginalValueReadOnceAndRestore;
//}
//
//@end

CC3OpenGLES11StateTrackerFogFloat::CC3OpenGLES11StateTrackerFogFloat()
{
}

CC3OpenGLES11StateTrackerFogFloat::~CC3OpenGLES11StateTrackerFogFloat()
{
}

CC3OpenGLES11StateTrackerFogFloat* CC3OpenGLES11StateTrackerFogFloat::trackerForState(GLenum aName)
{
	CC3OpenGLES11StateTrackerFogFloat* pState = new CC3OpenGLES11StateTrackerFogFloat;
	if (pState) 
	{
		pState->autorelease();
		pState->initForState(aName, NULL);
		return pState;
	}
	
	return NULL;
}

void CC3OpenGLES11StateTrackerFogFloat::setGLValue()
{
	glFogf(name, value);
}

CC3GLESStateOriginalValueHandling CC3OpenGLES11StateTrackerFogFloat::defaultOriginalValueHandling()
{
	return kCC3GLESStateOriginalValueReadOnceAndRestore;
}

#pragma mark -
#pragma mark CC3OpenGLES11StateTrackerFogEnumeration

//@implementation CC3OpenGLES11StateTrackerFogEnumeration
//
//-(void) setGLValue {
//	glFogx(name, value);
//}
//
//+(CC3GLESStateOriginalValueHandling) defaultOriginalValueHandling {
//	return kCC3GLESStateOriginalValueReadOnceAndRestore;
//}
//
//@end

CC3OpenGLES11StateTrackerFogEnumeration::CC3OpenGLES11StateTrackerFogEnumeration()
{
}

CC3OpenGLES11StateTrackerFogEnumeration::~CC3OpenGLES11StateTrackerFogEnumeration()
{
}

CC3OpenGLES11StateTrackerFogEnumeration* CC3OpenGLES11StateTrackerFogEnumeration::trackerForState(GLenum aName)
{
	CC3OpenGLES11StateTrackerFogEnumeration* pState = new CC3OpenGLES11StateTrackerFogEnumeration;
	if (pState) 
	{
		pState->autorelease();
		pState->initForState(aName, NULL);
		return pState;
	}
	
	return NULL;
}

void CC3OpenGLES11StateTrackerFogEnumeration::setGLValue()
{
	glFogx(name, value);
}

CC3GLESStateOriginalValueHandling CC3OpenGLES11StateTrackerFogEnumeration::defaultOriginalValueHandling()
{
	return kCC3GLESStateOriginalValueReadOnceAndRestore;
}

#pragma mark -
#pragma mark CC3OpenGLES11Fog

//@implementation CC3OpenGLES11Fog
//
//@synthesize color;
//@synthesize mode;
//@synthesize density;
//@synthesize start;
//@synthesize end;
//
//-(void) dealloc {
//	[color release];
//	[mode release];
//	[density release];
//	[start release];
//	[end release];
//	[super dealloc];
//}
//
//-(void) initializeTrackers {
//	self.color = [CC3OpenGLES11StateTrackerFogColor trackerForState: GL_FOG_COLOR];
//	self.mode = [CC3OpenGLES11StateTrackerFogEnumeration trackerForState: GL_FOG_MODE];
//	self.density = [CC3OpenGLES11StateTrackerFogFloat trackerForState: GL_FOG_DENSITY];
//	self.start = [CC3OpenGLES11StateTrackerFogFloat trackerForState: GL_FOG_START];
//	self.end = [CC3OpenGLES11StateTrackerFogFloat trackerForState: GL_FOG_END];
//}
//
//-(void) open {
//	LogTrace("Opening %@", [self class]);
//	[color open];
//	[mode open];
//	[density open];
//	[start open];
//	[end open];
//}
//
//-(void) close {
//	LogTrace("Closing %@", [self class]);
//	[color close];
//	[mode close];
//	[density close];
//	[start close];
//	[end close];
//}
//
//-(NSString*) description {
//	NSMutableString* desc = [NSMutableString stringWithCapacity: 600];
//	[desc appendFormat: @"%@:", [self class]];
//	[desc appendFormat: @"\n    %@ ", color];
//	[desc appendFormat: @"\n    %@ ", mode];
//	[desc appendFormat: @"\n    %@ ", density];
//	[desc appendFormat: @"\n    %@ ", start];
//	[desc appendFormat: @"\n    %@ ", end];
//	return desc;
//}
//
//@end

CC3OpenGLES11Fog::CC3OpenGLES11Fog() :
	color(NULL),
	mode(NULL),
	density(NULL),
	start(NULL),
	end(NULL)
{
	
}

CC3OpenGLES11Fog::~CC3OpenGLES11Fog()
{
	color->release();
	mode->release();
	density->release();
	start->release();
	end->release();
}

CC3OpenGLES11Fog* CC3OpenGLES11Fog::tracker()
{
	CC3OpenGLES11Fog* pState = new CC3OpenGLES11Fog;
	if (pState) 
	{
		pState->initializeTrackers();
		pState->autorelease();
	}
	
	return pState;
}

void CC3OpenGLES11Fog::open()
{
	//LogTrace("Opening %@", [self class]);
	color->open();
	mode->open();
	density->open();
	start->open();
	end->open();
}

void CC3OpenGLES11Fog::close()
{
	//LogTrace("Closing %@", [self class]);
	color->close();
	mode->close();
	density->close();
	start->close();
	end->close();
}

void CC3OpenGLES11Fog::initializeTrackers()
{
	setColor(CC3OpenGLES11StateTrackerFogColor::trackerForState(GL_FOG_COLOR));
	setMode(CC3OpenGLES11StateTrackerFogEnumeration::trackerForState(GL_FOG_MODE));
	setDensity(CC3OpenGLES11StateTrackerFogFloat::trackerForState(GL_FOG_DENSITY));
	setStart(CC3OpenGLES11StateTrackerFogFloat::trackerForState(GL_FOG_START));
	setEnd(CC3OpenGLES11StateTrackerFogFloat::trackerForState(GL_FOG_END));
}
